import lawBankTopBar from 'components/lawBankTopBar/lawBankTopBar'
import { getPolicyDataList } from '@/api/lawBank'
import { hightLightText } from '@/utils/utils'
import { checkView } from '@/api/checkView.js'
export default {
  components: {
    lawBankTopBar,
  },
  data() {
    return {
      title: '税收法规库',
      showPopup: false,
      tipsMsg: '今日免费次数已用完，请您充值成为会员，以享受更多精彩的功能和服务。',
      contentTopHeight: 0,
      backgroundUrl: require('@/static/img/lawBank/topBar_bg_01.png'),
      searchText: '',
      scrollTop: 0,
      sortList: [{
        id: 1,
        nid: 1,
        name: '热点法规'
      }, {
        id: 2,
        nid: 2,
        name: '中央法规'
      }, {
        id: 3,
        nid: 3,
        name: '地方法规'
      }, {
        id: 27,
        name: '海关综合文件'
      }, {
        id: 20,
        name: '国际跨境税收'
      }, {
        id: 28,
        name: '外汇文件'
      }, {
        id: 32,
        name: ' 12366热点问答'
      }, {
        nid: 4,
        name: '法规法条'
      }], //分类
      chooseTagId: 1,
      keyword: '',
      form: {
        keyword: '', //	否	string	搜索字段
        city_code: '', //	否	string	城市编码
        policy_cate_id: '',
        is_hot: 1,
        is_fatiao: '', //是否法规发条 1：是 0：否
        title_keyword: '', //标题关键字
        cons_keyword: '', //内容关键字
      },
      query: {
        type: 2, //	是	string	类型:1=优惠政策,2=税收法规
        page: 1,
        limit: 10,
        maxpage: 1
      },
      isLoading: false,
      loadMoreStatue: 'more',
      count: 0,
      lawList: [],
      isRefreshing: false,
      loadMoreStatus: 'more',
      isSearch: false,//判断是否是高级搜索页跳转过来的
      isSearch1: false,
      flag: false,
    };
  },
  methods: {

    //高亮
    hightLightText(text, keyword) {
      return hightLightText(text, keyword)
    },
    //去搜索
    goSearch() {
      this.lawList = [];
      this.form.keyword = this.keyword
      this.isSearch1 = this.keyword == '' ? false : true
      this.query.page = 1;
      this.form.is_hot = '';
      this.form.city_code = '';
      this.title = this.form.keyword ? '搜索结果' : '税收法规库';
      this.getList()
    },
    //去高级搜索页面
    goHighSearch(type) {
      uni.removeStorageSync('searchQuery');
      uni.navigateTo({
        url: `/lawBank/highSearch/highSearch?type=${type}`
      })
    },

    //选择分类
    chooseTag(e) {
      this.chooseTagId = e.id;

      this.form.is_fatiao = '';
      this.form.policy_cate_id = '';
      this.form.is_hot = '';
      this.form.city_code = '';
      this.query.page = 1;
      if (e.nid == 1) {
        this.form.is_hot = 1;
      } else if (e.nid == 2) {
        this.form.city_code = 1;
      } else if (e.nid == 3) {
        this.form.city_code = -1;
      } else if (e.nid == 4) {
        this.form.is_fatiao = 1;
      } else {
        this.form.policy_cate_id = e.id;
      }
      this.lawList = [];
      this.getList();
    },

    //请求列表数据
    getList() {
      if (this.query.page == 1) {
        this.dataList = [];
        this.isLoading = true;
      } else {
        this.loadMoreStatue = 'loading';
      }
      let queryData = { ...this.form, ...this.query }
      getPolicyDataList(queryData).then(res => {
        if (res.code == 1) {
          if (res.data.length > 0) {
            this.count = res.data[0].all_count;
          } else {
            this.count = 0;
          }
          if (this.query.page == 1) {
            this.lawList = [];
          }
          var newList = res.data;
          if (newList.length >= this.query.limit) {
            this.loadMoreStatus = 'more';
          } else {
            this.loadMoreStatus = 'noMore';
          }
          this.lawList = [...this.lawList, ...newList];
          this.isRefreshing = false;
        } else {
          this.$tools.showToast(res.msg);
          this.loadMoreStatus = 'noMore';
        }
      })
    },

    //下拉刷新
    reload() {
      this.query.page = 1;
      this.lawList = [];
      this.isRefreshing = true;
      this.getList()
    },

    //加载更多
    loadMore() {
      if (this.loadMoreStatus == 'more') {
        this.query.page++;
        console.log(this.query.page);
        this.getList()
      } else {
        this.$used.msg('没有更多了');
      }
    },

    //去詳情
    toInfo(id) {
      checkView({ id }).then(res => {
        if (res.code == -100) {
          this.showPopup = true
        } else {
          uni.navigateTo({
            url: "./revenueInfo?id=" + id
          })
        }
      })
    },

  },
  onReady() {

  },
  onShow() {
  },
  onLoad(e) {
    let { isSearch } = e
    if (isSearch) {
      this.isSearch = isSearch
      let data = uni.getStorageSync('searchQuery')
      this.form = data
      this.title = '搜索结果'
      this.getList()
    } else {
      this.getList()
    }
  },

}